<?php

class Ext_Captcha_Show
{
    protected static $_instance = null;
    
    public static function getInstance()
    {
        if (null === self::$_instance) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }

    public function __construct()
    {
        
    }

    public function buildOnlyCaptcha()
    {
        return $this->buildFormElement()->getCaptcha();
    }

    public function buildFormElement()
    {
        $translate = Zend_Registry::get('Zend_Translate');
        
        $decorators = array(
            array(
                'HtmlTag', 
                array(
                    'tag'     => 'div',
                    'id'      => 'captchaId',
                    'onclick' => 'changeImage()',
                )
            )
        );
        
        $decorators = array(
            array('Description', array('class' => 'tip', 'tag' => "div", 'id' => "tip-captcha")),
            array('HtmlTag', array('tag' => 'dd', 'class' => 'captcha')),
            array('Label', array('tag' => 'dt')),
            'Errors',
        );
 
        $config = Ext_Config::getInstance()->getConfig('image');
        $formElement = new Zend_Form_Element_Captcha(  
            'captcha', // This is the name of the input field  
            array(
                'label'   => $translate->_("Captcha"),  
                'captcha' => array( // Here comes the magic...  
                    'captcha'       => 'Image',
                    'wordLen'       => 4,
                    'fontsize'      => 20,
                    'width'         => 120,
                    'height'        => 60,
                    'dotNoiseLevel' => 2,
                    'timeout'       => 300,  
                    'font'          => APPLICATION_PATH.'/data/fonts/FetteSteinschrift.ttf',
                    'imgDir'        => $config->captcha->dir,
                    'imgUrl'        => $config->captcha->url, 
                ),
                'decorators' => $decorators,
                'description'=> "Please write the chars to the field. Click the captcha to generate a new one.",
           )
        );
        $formElement->setRequired(true)
                 ->addValidator('NotEmpty')
                 ->setAttrib('validate', '{required:true}');
        $formElement->getCaptcha()->setGcFreq(3);
        
        return $formElement;
    }
}
